package com.anlen.call.ui;

import android.app.TabActivity;
import android.content.Intent;
import android.os.Bundle;
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.RadioButton;
import android.widget.TabHost;

import com.anlen.call.R;

/**
 * 标签类
 * @author anlen
 *
 * @date 2015-8-24
 */
@SuppressWarnings("deprecation")
public class Tab_downActivity extends TabActivity implements OnCheckedChangeListener{


	private TabHost myTabHost;

	private Intent indexIntent;
	private Intent moreIntent;
	private Intent extraIntent;

	private RadioButton rbIndex;
	private RadioButton rbMore;
	private RadioButton rbExtra;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		
		super.onCreate(savedInstanceState);
		
		setContentView(R.layout.bottom_tab);

		indexIntent = new Intent(this, IndexActivity.class);

		moreIntent = new Intent(this, MoreActivity.class);
		extraIntent = new Intent(this,ExtraActivity.class);
		
		rbIndex = (RadioButton) findViewById(R.id.rbPurBottomTabToIndex);
		rbMore = (RadioButton) findViewById(R.id.rbPurBottomTabToMore);
		rbExtra = (RadioButton) findViewById(R.id.news);
		
		rbIndex.setOnCheckedChangeListener(this);
		rbMore.setOnCheckedChangeListener(this);
		rbExtra.setOnCheckedChangeListener(this);
		
		setupIntent();

		myTabHost.setCurrentTabByTag("INDEX");
	}


	@Override
	public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
		buttonView.setTextColor(this.getResources().getColor(R.color.assist_gray_font));
		if (isChecked) {
			switch (buttonView.getId()) {
				case R.id.rbPurBottomTabToIndex:
					rbIndex.setTextColor(this.getResources().getColor(R.color.white));
					myTabHost.setCurrentTabByTag("INDEX");
					break;
				case R.id.rbPurBottomTabToMore:
					rbMore.setTextColor(this.getResources().getColor(R.color.white));
					myTabHost.setCurrentTabByTag("MORE");
					break;
				case R.id.news:
					rbExtra.setTextColor(this.getResources().getColor(R.color.white));
					myTabHost.setCurrentTabByTag("news");
					break;
				default:
					break;
			}
		}
	}

	private void setupIntent() {
		this.myTabHost = getTabHost();
		TabHost localTabHost = this.myTabHost;

		localTabHost.addTab(buildTabSpec("INDEX", R.string.strhome,R.drawable.home, this.indexIntent));
		localTabHost.addTab(buildTabSpec("MORE", R.string.more,R.drawable.more,this.moreIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)));
		localTabHost.addTab(buildTabSpec("news", R.string.news,R.drawable.supplier,this.extraIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)));

	}

	private TabHost.TabSpec buildTabSpec(String tag, int resLabel, int resIcon,final Intent content) {
		return this.myTabHost.newTabSpec(tag).setIndicator(getString(resLabel)).setContent(content);
	}
//
//	@Override
//	public boolean onCreateOptionsMenu(Menu menu) {
//		getMenuInflater().inflate(R.menu.main, menu);
//		return true;
//	}

	
}
